﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Com.Charence.PassManager.BusinessEntities;
using Com.Charence.PassManager.BusinessEntities.Account;
using Com.Charence.PassManager.DataComponents;
using Com.Charence.PassManager.Common.Extensions;

namespace Com.Charence.PassManager.BusinessComponents
{
    public class AccountBC
    {
        private readonly AccountDC _dc = new AccountDC();

        public void SaveNewAccount(SaveAccountRequest request)
        {
            _dc.SaveNewAccount(request);
        }

        public List<AccountBase> GetAccountGrid(string keywords)
        {
            var keywordsList = (keywords ?? string.Empty).Split(' ').ToList();
            var accountList = _dc.GetAccountGrid(keywordsList);
            if (string.IsNullOrEmpty(keywords))
            {
                accountList = accountList.Take(10).ToList();
            }
            accountList.ForEach(p => {
                if (!string.IsNullOrEmpty(p.Password))
                    p.Password = p.Password.Decrypt();
            });
            return accountList;
        }
    }
}
